package com.xej.seat.test;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.xej.seat.seating.Seating;
import com.xej.seat.service.CustomerService;
import com.xej.seat.service.HallService;
import com.xej.seat.service.SeatService;
import com.xej.seat.vo.Customer;
import com.xej.seat.vo.Hall;
import com.xej.seat.vo.Seat;

@RunWith(SpringRunner.class)
@SpringBootTest
public class SeatMain {
	
	@Autowired
	private CustomerService customerService;
	
	@Autowired
	private SeatService seatService;
	
	@Autowired
	private HallService hallService;
	
	@Autowired
	private Seating Seating;
	
	/**
	 * 创建会场
	 */
	@Test
	public void createHall() {
		try {
			Hall hall = new Hall("第一个会场", 3, 3);
			this.hallService.createHallSeat(hall);
		} catch(Exception e) {
			e.getStackTrace();
		}
	}
	
	
	/**
	 * 排座
	 */
	@Test
	public void seating() {
		try {
			Hall hall = this.hallService.queryHallById("12");
			this.Seating.seating(hall);
			System.out.println();
			for(Seat seat : hall.getList()) {
			}
			System.out.println(JSONObject.parseObject(JSON.toJSONString(hall)));
			System.out.println(JSON.toJSON(hall));
			System.out.println(JSON.toJSONString(hall));
//			for(Seat seat : hall.getSeatList()) {
//				System.out.println("第" + seat.getSrow() + "排，第" + seat.getScol() + "列，权重-->" + seat.getWeight());
//			}
//			for(Customer customer : hall.getCustomers()) {
//				System.out.println("姓名：" + customer.getCusName() + "，权重-->" + customer.getWeight());
//			}
//			System.out.println("----------------->");
//			Collections.sort(hall.getSeatList());
//			for(Seat seat : hall.getSeatList()) {
//				System.out.println("第" + seat.getSrow() + "排，第" + seat.getScol() + "列，权重-->" + seat.getWeight());
//			}
//			System.out.println("----------------->");
//			Collections.sort(hall.getCustomers());
//			for(Customer customer : hall.getCustomers()) {
//				System.out.println("姓名：" + customer.getCusName() + "，权重-->" + customer.getWeight());
//			}
		} catch(Exception e) {
			e.getStackTrace();
		}
	}
	
	@Test
	public void queryCustomer() {
		try {
			Customer customers = this.customerService.queryCustomerById("1");
			System.out.println(customers);
		} catch(Exception e) {
			e.getStackTrace();
		}
	}
	
	@Test
	public void querySeat() {
		try {
			Map<String, Object> params = new HashMap<String, Object>();
			params.put("sid", 128);
			List<Seat> seats = this.seatService.querySeatByParams(params);
			System.out.println("---->" + seats);
		} catch(Exception e) {
			e.getStackTrace();
		}
	}
	
}
